import { globalPlayer } from 'python-player';

const EXAMPLE1_CONTENT = `# 示例1：基础计算
# 这个示例展示了基本的数学运算

def calculate_circle_area(radius):
    """计算圆的面积"""
    import math
    return math.pi * radius ** 2

def calculate_circle_perimeter(radius):
    """计算圆的周长"""
    import math
    return 2 * math.pi * radius

def main():
    print("=== 圆的计算器 ===")
    
    try:
        radius = float(input("请输入圆的半径: "))
        
        if radius <= 0:
            print("半径必须大于0!")
            return
        
        area = calculate_circle_area(radius)
        perimeter = calculate_circle_perimeter(radius)
        
        print(f"\\n计算结果:")
        print(f"半径: {radius}")
        print(f"面积: {area:.2f}")
        print(f"周长: {perimeter:.2f}")
        
    except ValueError:
        print("请输入有效的数字!")

if __name__ == "__main__":
    main()`;

const EXAMPLE2_CONTENT = `# 示例2：列表操作
# 这个示例展示了Python列表的各种操作

def list_operations_demo():
    """列表操作演示"""
    print("=== 列表操作演示 ===")
    
    # 创建列表
    numbers = [1, 2, 3, 4, 5]
    print(f"原始列表: {numbers}")
    
    # 添加元素
    numbers.append(6)
    print(f"添加6后: {numbers}")
    
    # 插入元素
    numbers.insert(0, 0)
    print(f"在开头插入0: {numbers}")
    
    # 删除元素
    numbers.remove(3)
    print(f"删除3后: {numbers}")
    
    # 列表推导式
    squares = [x**2 for x in numbers]
    print(f"平方列表: {squares}")
    
    # 过滤
    even_numbers = [x for x in numbers if x % 2 == 0]
    print(f"偶数: {even_numbers}")
    
    # 排序
    numbers.sort(reverse=True)
    print(f"降序排列: {numbers}")

if __name__ == "__main__":
    list_operations_demo()`;

export const createBasicExamplesFolder = () => {
  try {
    // 创建examples文件夹
    const dir = globalPlayer.fs.createDirObject('examples', {
      parentId: 0,
      id: 4, // 使用数字ID
      opened: false
    });

    // 创建circle_calculator.py
    const circleCalculator = globalPlayer.fs.createFileObject('circle_calculator.py', {
      parentId: dir.id,
      id: 5, // 使用数字ID
      opened: false
    });
    circleCalculator.setContentSync(EXAMPLE1_CONTENT);

    // 创建list_operations.py
    const listOperations = globalPlayer.fs.createFileObject('list_operations.py', {
      parentId: dir.id,
      id: 6, // 使用数字ID
      opened: false
    });
    listOperations.setContentSync(EXAMPLE2_CONTENT);

    // console.log('默认基础示例文件夹及子文件创建成功:', dir.name, 'ID:', dir.id);
    return [dir, circleCalculator, listOperations];
  } catch (error) {
    console.error('创建默认基础示例文件夹失败:', error);
    throw error;
  }
};
